package com.wood.life.controller;

import com.night.common.entity.ResultVo;
import com.night.common.entity.life.Answer;
import com.night.common.entity.life.Question;
import com.night.common.entity.life.QuestionVo;
import com.wood.life.service.AnswerService;
import com.wood.life.service.QuestionService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * author: dz
 * 2022-10-18-19:14
 */
@RestController
@RequestMapping("/api/life/question")
public class QuestionController {
    @Autowired
    QuestionService questionService;
    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("/add")
    public ResultVo add(@RequestBody QuestionVo questionVo) {
        rabbitTemplate.convertAndSend("exchangetopic", "question", questionVo);
        return new ResultVo<>(200,"queue",questionVo);
    }

    @RequestMapping("/getAll")
    public ResultVo getAll() {
        Question question=new Question();
        question.setStatus("y");
        System.out.println(questionService.getByCondition(question));
        return new ResultVo<>(questionService.getByCondition(question));
    }

    @RequestMapping("/getById")
    public ResultVo getById(int id) {
        System.out.println(questionService.getById(id));
        return new ResultVo<>(questionService.getById(id));
    }
}
